package com.wafer.server.util;

import java.io.File;
import java.util.LinkedList;
import java.util.List;

public class PackageUtil {
	
	/**
	 * 将包名替换为绝对路径
	 * @todo TODO
	 * @param packageName
	 * @return
	 */
    public static List<String> getClassName(String packageName) {  
        String filePath = ClassLoader.getSystemResource("").getPath() + packageName.replace(".", "/");  
        System.out.println("绝对路径:" + filePath);
        List<String> fileNames = getClassName(filePath, null);                                                                                                                    
        return fileNames;  
    }  
  
    /**
     * 遍历包(不包括子包)并返回所有文件名
     * @todo TODO
     * @param filePath
     * @param className
     * @return
     */
    private static List<String> getClassName(String filePath, List<String> className) {  
        List<String> myClassName = new LinkedList<String>();
        File file = new File(filePath);  
        File[] childFiles = file.listFiles();  
        for (File childFile : childFiles) {  
        	if(childFile.getName().endsWith(".class")){
        		myClassName.add(childFile.getName());
        	}
        }
        return myClassName;  
    }     
    
	
/*    public static void main(String[] args) {  
        String packageName = "com.wafer.server.filter";  
  
        List<String> classNames = getClassName(packageName);  
        for (String className : classNames) {  
            System.out.println(className);  
        }  
    }*/  

}
